define(['app'], function(app) {
    'use strict';

    //实例化方法
    var factory = function(Http) {

        //编辑求购信息返回
        function get_data_updatelist(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"title": "求购扳手","id": "001","end_time": "2017/01/01 23:59:59","address": "上大路沪太路","invoice_type": "2","phone": "18912345678","memo": "","goods": [{"name": "扳手","describe": "","cat_type": "手动工具/扳手/活络扳手","brand_need": true,"brand_name": "东成","count": 2,"photo": [{"id": "001","image": "001.jpg"},{"id": "002","image": "002.jpg"}]},{"name": "扳手2","describe": "","cat_type": "手动工具/扳手/活络扳手","brand_need": true,"brand_name": "东成","count": 2,"photo": [{"id": "001","image": "001.jpg"},{"id": "002","image": "002.jpg"}]}],"offer_list": [{"offer_time": "2017/01/01 08:30:00","store_name": "东成1","area": "江苏东城","price": 5},{"offer_time": "2017/01/01 08:30:00","store_name": "东成2","area": "江苏东城","price": 5}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

        //添加求购
        function get_data_add(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"info_id":"001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

        //返回信息
        return {
            //保存
            save_getlist: function(title, id, end_time, address_id, invoice_type, phone, memo, goods, callback) {
                var params=new Object();
                params.title=title;
                params.id=id;
                params.end_time=end_time;
                params.address_id=address_id;
                params.invoice_type=invoice_type;
                params.phone=phone;
                params.memo=memo;
                params.goods=goods;
                params=JSON.stringify(params);
                Http.post({
                    method: 'info.findgoods.edit',
                    updateParams: params
                }, function(result) {
                    //请求成功
                    if(callback)
                        callback(get_data_add(result));
                }, function(e) {
                    //请求异常
                }, function() {
                    //请求完成，一般不做什么事情
                });
            },
            //编辑信息返回
            update_goods: function(id, callback) {
                Http.post({
                        method: 'info.findgoods.detail',
                        id: id
                    },
                    function(result) {
                        //函数回调
                        if(callback)
                            callback(get_data_updatelist(result).result);
                    },
                    function(e) {

                    },
                    function() {

                    });
            }
            

        };
    }

    factory.$inject = ['Http'];
    return app.registerService("Mypbuy_edit", factory);
});